home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4313 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: ornews.intel.com!news
  2. From: thurman_b_miller@ccm2.hf.intel.com (Thurman Miller)
  3. Newsgroups: comp.lang.c++
  4. Subject: Conversion routines needed
  5. Date: Mon, 29 Jan 1996 18:26:58 GMT
  6. Organization: Intel Corporation
  7. Message-ID: <4ej3j9$49d@ornews.intel.com>
  8. NNTP-Posting-Host: thurman-pc.co.intel.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. I'm fairly new to C++. I'm confident in how classes work and have had
  12. fun using this new approach. However, I came into this with about zero
  13. experience in C, so I'm having loads of problems trying to convert
  14. something to another thing. 
  15.  
  16. My ultimate goal is for someone to recommend a great book or a good
  17. chapter in a worthless book, or somewhere inbetween. Saying that, here
  18. are some specific examples that have given me grief over the past
  19. week:
  20.  
  21. I'm trying to interface into a 3rd party product. Their definitions
  22. are as follows:
  23.  
  24. typedef unsigned char  RFC_CHAR;   
  25. typedef RFC_CHAR SAP_MATNR[18];
  26. typedef RFC_CHAR SAP_PLANT[4];
  27.  
  28.  
  29. Now, I've got (Using MS Visual C++)
  30.  
  31. CString material;
  32. int nChars = GetDlgItemText(IDC_MATERIAL, material.GetBuffer(18),18); 
  33. static SAP_MATNR sap_mat;
  34. // For some reason, material.GetLength() was returning zero.
  35. memcpy( sap_mat, material, nChars);
  36.  
  37. CString plantname;
  38. int nIndex = m_cboPlant.GetCurSel();
  39. m_cboPlant.GetLBText(nIndex,plantname);
  40.  
  41. static SAP_PLANT sap_plant;
  42. // Why GetLength worked here and not above, I've no idea.
  43. memcpy( sap_plant, plantname, plantname.GetLength() );
  44.  
  45.  
  46. I need to make the following call:
  47.  
  48.         int      z_getmat    
  49.             (RFC_HANDLE hRfc,
  50.               SAP_MATNR * pMatnbr,
  51.               SAP_PLANT * pPlntno, 
  52.               ITAB_H hMarcTable,
  53.               char * pException 
  54.             );
  55.  
  56. so I used the following:
  57.  
  58. int nRet =   z_getmat(hRfc,&sap_mat,&sap_plant,phMarcTable,errorstr); 
  59.  
  60.  
  61. In all honesty, I did this by blindly trying about 100 different
  62. things and I'm at a point to where the whole contraption works, but
  63. I've more or less lost my way as to how I got here.
  64.  
  65. A couple of questions:
  66.  
  67. 1. I mistakenly assumed that:
  68.  
  69. RFC_CHAR SAP_MATNR[18] is the same as
  70. typedef RFC_CHAR SAP_MATNR[18]
  71.  
  72. Why aren't these equivalent?
  73.  
  74. 2. An unsigned char, is apparently a integer value from 0-255, so why
  75. doesn't the following type-cast work?
  76.  
  77. CString sap_mat = (CString)SAP_MATNR;
  78.  
  79. 3. Memcpy seems so "Cish". Is there a better way to convert?
  80.  
  81. 4. Why does a "&sap_plant" = "* sap_plant"
  82.  
  83.  
  84. Any help appreciated!
  85.  
  86. Thurman Miller
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.